import datetime
import random

from django.db import models

from user.models import User, Address
from work.models import Good
# Create your models here.

#  口味菜品关系
class TasteGood(models.Model):
    some_taster = models.CharField(max_length=64, verbose_name='具体口味')
    # 外键关联
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    good_id = models.ForeignKey(Good,on_delete=models.CASCADE,verbose_name='菜品')

    class Meta:
        db_table = 'taste_good'

# 订单
class Order(models.Model):
    order_id = models.CharField(max_length=128, primary_key=True, verbose_name='订单编号',default=random.randint(00000,99999))
    create_time = models.DateTimeField(default=datetime.datetime.now, verbose_name='创建时间')
    status = models.IntegerField(choices=((0,'待支付'),(1,'待派送'),(2,'派送中'),(3,'已完成')),default=0,
                                 verbose_name='0:待支付,1:代派送,2:派送中,3:已完成')
    money = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='总价格')
    info = models.CharField(max_length=64, verbose_name='备注')
    type = models.IntegerField(verbose_name='0:支付宝,1:微信')
    # 外键关系
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    address = models.ForeignKey(Address, on_delete=models.CASCADE, verbose_name='收获地址')

    class Meta:
        db_table = 'order'


# 商品订单
class GoodOreder(models.Model):
    num = models.IntegerField(verbose_name='数量')
    price = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='商品价格')
    comment = models.TextField(verbose_name='评价')
    score = models.SmallIntegerField('评分', choices=((0, '0星'), (1, '1星'), (2, '2星'), (3, '3星'), (4, '4星'), (5, '5星')))
    is_anonymous = models.BooleanField('是否匿名评价', default=False)
    is_commented = models.BooleanField('是否评价', default=False)
    # 外键关系
    order = models.ForeignKey(Order, on_delete=models.CASCADE, verbose_name='订单')
    goods = models.ForeignKey(Good,on_delete=models.CASCADE,verbose_name='商品')

    class Meta:
        db_table = 'goodoreder'
